/* Copyright 2009
 *
 * This program and the accompanying materials
 * are made available under the terms of the
 * Eclipse Public License v1.0 which accompanies
 * this distribution, and is available at
 *
 * 		http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in
 * writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
 * OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * Contributors:
 * 	   IBM Corporation - initial API and implementation for JDT/DLTK
 *     Sean W. Quinn - initial adoption for use with PHP from various sources.
 */
package org.eclipse.php.internal.core;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.dltk.core.ModelException;
import org.eclipse.dltk.internal.core.OpenableElementInfo;

/**
 * Element info for NamespaceFragments.
 */
@SuppressWarnings("restriction")
class NamespaceFragmentInfo extends OpenableElementInfo {

	/**
	 * A array with all the non-java resources contained by this
	 * NamespaceFragment
	 */
	protected Object[] nonPHPResources;

	/**
	 * Create and initialize a new instance of the receiver
	 */
	public NamespaceFragmentInfo() {
		this.nonPHPResources = null;
	}

	/**
	 *
	 */
	boolean containsPHPResources() {
		return this.getChildren().length != 0;
	}

	/**
	 * Returns an array of non-java resources contained in the receiver.
	 *
	 * @throws ModelException
	 */
	Object[] getNonPHPResources(final IResource underlyingResource, final NamespaceFragmentRoot rootHandle) {
		if (this.nonPHPResources == null) {
			try {
				this.nonPHPResources = NamespaceFragmentRootInfo.computeFolderNonPHPResources(rootHandle,
						(IContainer) underlyingResource, rootHandle.fullInclusionPatternChars(), rootHandle
								.fullExclusionPatternChars());
			}
			catch (ModelException e) {
				// root doesn't exist: consider package has no nonJavaResources
				this.nonPHPResources = NO_NON_SCRIPT_RESOURCES;
			}
		}
		return this.nonPHPResources;
	}

	/**
	 * Set the nonJavaResources to res value
	 */
	void setNonPHPResources(Object[] resources) {
		this.nonPHPResources = resources;
	}
}
